package com.topone.config;

import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.Arrays;


//@Configuration
//@EnableSwagger2
//public class SwaggerConfig extends WebMvcConfigurerAdapter {
//
//    private final static Logger log = Logger.getLogger(SwaggerConfig.class);
//
//    @Override
//    public void addResourceHandlers(ResourceHandlerRegistry registry) {
//        //enabling swagger-ui part for visual documentation
//        registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
//        registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/");
//    }
//
//    @Bean
//    public Docket api() {
//        log.info("Swagger startup");
////        Parameter headerParam = new ParameterBuilder().name("X-MG-AUTH-TOKEN").parameterType("header")
////                .modelRef(new ModelRef("string")).description("Authentication").required(false).build();
//
//        return new Docket(DocumentationType.SWAGGER_2)
//                .apiInfo(apiInfo())
//                .select()
//                .apis(RequestHandlerSelectors.basePackage("com.topone.controller"))
//                .paths(PathSelectors.any())
//                .build();
//    }
//    private ApiInfo apiInfo() {
//        ApiInfo apiInfo = new ApiInfo(
//                "fanZone REST API",
//                "fanZone REST API for Service Pack",
//                "1.0",
//                "Terms of service",
//                new Contact("fanZone", "", ""),"","");
//        return apiInfo;
//    }
//}


/**
 *
 * @author james
 */
@Configuration
@EnableSwagger2
public class SwaggerConfig extends WebMvcConfigurerAdapter {

    protected final org.slf4j.Logger LOG = LoggerFactory.getLogger(getClass());


    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.topone.controller"))
                .paths(PathSelectors.ant("/**"))
                .build();
    }
    private ApiInfo apiInfo() {
        LOG.info("Swagger startup");
        return new ApiInfoBuilder()
                .title("fanZone聚汇 api")
                .description("看不懂找我呀！我告诉你")
                .termsOfServiceUrl("")
                .contact("")
                .version("1.0")
                .build();
    }
//    @Override
//    public void addResourceHandlers(ResourceHandlerRegistry registry) {
//        //enabling swagger-ui part for visual documentation
//        registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
//        registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
//    }
//
//    @Bean
//    public Docket api() {
//        LOG.info("Swagger startup");
//        Parameter headerParam = new ParameterBuilder().name("X-MG-AUTH-TOKEN").parameterType("header")
//                .modelRef(new ModelRef("string")).description("Authentication").required(false).build();
//
//        return new Docket(DocumentationType.SWAGGER_2)
//                .globalOperationParameters(Arrays.asList(headerParam))
//                .select()
//                .apis(RequestHandlerSelectors.basePackage("com.topone.controller"))
//                .paths(PathSelectors.ant("/**"))
//                .build();
//    }
}
